package com.jf.hotelreservation.demos.utils;

import lombok.Data;

import java.io.Serializable;

@Data
public class R implements Serializable {

    private final static int SUCCESS_CODE = 200;
    private final static int ERROR_CODE = 500;

    private int code;
    private String msg;
    private Object data;

    public static R success(String msg){
        R m = new R();
        m.setCode(SUCCESS_CODE);
        m.setMsg(msg);
        return m;
    }
    public static R success(){
        R m = new R();
        m.setCode(SUCCESS_CODE);
        m.setMsg("操作成功");
        return m;
    }
    public static R success(Object data) {
        R m = new R();
        m.setCode(SUCCESS_CODE);
        m.setData(data);
        m.setMsg("操作成功");
        return m;
    }
    public static R success(String mess, Object data) {
        R m = new R();
        m.setCode(SUCCESS_CODE);
        m.setData(data);
        m.setMsg(mess);
        return m;
    }
    public static R error(String mess) {
        R m = new R();
        m.setCode(ERROR_CODE);
        m.setData(null);
        m.setMsg(mess);
        return m;
    }
    public static R error(String mess, Object data) {
        R m = new R();
        m.setCode(ERROR_CODE);
        m.setData(data);
        m.setMsg(mess);
        return m;
    }
}
